﻿using System;
using System.ServiceModel;
using System.ServiceModel.Dispatcher;

namespace Zen4SyncDevelopmentHost
{
    class Program
    {
        static void Main(string[] args)
        {
            ServiceHost hostOrchestrator = new ServiceHost(typeof(Zen4SyncOrchestrator.OrchestratorServices));
            hostOrchestrator.Open();

            DisplayListeningConfiguration("OrchestratorServices", hostOrchestrator);

            ServiceHost hostTestServer = new ServiceHost(typeof(Zen4SyncTestServer.TestServerServices));
            hostTestServer.Open();
            
            DisplayListeningConfiguration("TestServerServices", hostTestServer);

            Console.WriteLine("\n\nServices are listening.");
            Console.WriteLine("Hit <Return> to close...");
            Console.ReadLine();

            hostOrchestrator.Close();
            hostTestServer.Close();
        }

        private static void DisplayListeningConfiguration(string serviceHosted, ServiceHost host)
        {
            Console.WriteLine("".PadRight(30, '#'));

            Console.WriteLine("{0} configuration :\n", serviceHosted);
            foreach (ChannelDispatcher binding in host.ChannelDispatchers)
            {
                Console.WriteLine("Binding : {0}", binding.BindingName);

                foreach (var endpoint in binding.Endpoints)
                {
                    Console.WriteLine("Endpoint : {0}", endpoint.EndpointAddress);
                }
                Console.WriteLine("".PadRight(15, '-'));
            }
        }
    }
}
